package com.scu.qingshi.infrastructure.utils;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * 文本与日期的转换工具
 *
 * @author qingshi
 */
public class DateUtil {

    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static Date Today(){
        return cn.hutool.core.date.DateUtil.parse(cn.hutool.core.date.DateUtil.today()).toJdkDate();
    }

    public static Date convertTZtoDate(String s) {
        return cn.hutool.core.date.DateUtil.parse(s, "yyyy-MM-dd hh:mm:ss").toJdkDate();
    }

    public static Date convertTextToDate(String s) throws ParseException {
        return sdf.parse(s);
    }

    public static boolean expirationDate(String date) throws ParseException {
        return DateUtil.expirationDate(DateUtil.convertTextToDate(date));
    }

    /**
     * 如果date在今天之前，则返回true，即"过期"日期
     * 以前 compareTo 未来 = -1
     */
    public static boolean expirationDate(Date date) {

        return date.compareTo(new Date()) <= 0;
    }

    public static String format(Date date) {
        return cn.hutool.core.date.DateUtil.format(date, "yyyy-MM-dd HH:mm:ss");
    }

    public static void main(String[] args) throws ParseException {
        String s = "2022-04-27T16:00:00.000Z";
//        Date date = DateUtil.convertTZtoDate(s);
//        System.out.println(date);

        LocalDateTime parse = LocalDateTime.parse(s);
        System.out.println(parse);
    }

}
